package com.wxg.other;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class UrlToString {
	private URL url;

	public UrlToString(URL url) {
		this.url = url;
	}
	
	/**
	 *  记住可以通过 `public URL(String spec)`来构造 URL即可！
	 *  用 Debug 来测试 URL 你会发现很奇葩的事情的！
	 *  还是不要去尝试 Debug 了。
	 *  即使 Debug 也最好使用 IntelliJ IDEA 来！~
	 * 
	 * @param url
	 * @throws MalformedURLException
	 */
	public UrlToString(String url) throws MalformedURLException {
		this.url = new URL(url);
	}
	
	public void test() throws IOException {
		InputStream is = url.openStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(is));
		try {
			String line = br.readLine();
			while (line != null) {
				System.out.println(line);
				line = br.readLine();
			}
		} finally {
			br.close();
		}
	}
	
	public static void main(String[] args) throws IOException {
		UrlToString urlToString = new UrlToString("https://www.cnblogs.com/blackiesong/p/6182038.html");
		urlToString.test();
	}
}
